package cn.wd.user.controller;


import cn.wd.common.vo.R;
import cn.wd.user.domain.entity.ConfigInfo;
import cn.wd.user.qo.ConfigInfoQueryObject;
import cn.wd.user.service.IConfigInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
// @Api(tags = "字典管理")
@RequestMapping("/configInfo")
public class ConfigInfoController {
    
    private final IConfigInfoService service;

    public ConfigInfoController(IConfigInfoService service) {
        this.service = service;
    }

    // @ApiOperation(value = "字典管理列表")
    @RequestMapping("/list")
    public R<Page<ConfigInfo>> query(ConfigInfoQueryObject qo) {
        return R.OK(service.listConfigInfoPage(qo));
    }

    // @ApiOperation(value = "字典数据列表", notes = "不包含分页数据")
    @RequestMapping("/all")
    public R<List<ConfigInfo>> all() {
        return R.OK(service.list());
    }

    // @ApiOperation(value = "编辑数据字典", notes = "根据主键是新增还是编辑")
    @RequestMapping("/saveOrUpdate")
    public R<?> saveOrUpdate(@RequestBody ConfigInfo configInfo) {
        if (configInfo.getId() != null) {
            service.updateById(configInfo);
        } else {
            service.save(configInfo);
        }

        return R.OK();
    }

    // @ApiOperation(value = "根据id删除字典", notes = "根据主键id删除数据字典")
    @RequestMapping("/delete")
    public R<?> delete(Long id) {
        if (id == null) {
            return R.FAIL("删除的 id 不能为空!");
        }

        service.removeById(id);
        return R.OK();
    }

    /**
     * 批量删除系统配置属性
     *
     * @param deletedIds ids 数组
     * @return
     */
    // @ApiOperation(value = "批量删除", notes = "根据主键id批量删除数据字典")
    @RequestMapping("/batchDelete")
    public R<?> batchDelete(@RequestBody(required = false) Long[] deletedIds) {
        service.batchDelete(deletedIds);
        return R.OK();
    }
}
